extends CharacterBody2D

@onready var anim: AnimatedSprite2D = $AnimatedSprite2D

var hp = 100
const SPEED = 200.0
const JUMP_VELOCITY = -300.0


func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta
	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		anim.play("Jump")
	#跳跃状态
	if velocity.y > 0:
		anim.play("Fall")
		
	var direction := Input.get_axis("left", "right")
	#水平方向
	if direction == -1:
		anim.flip_h = true
	else:
		anim.flip_h = false
	#水平移动和站立状态
	if direction:
		velocity.x = direction * SPEED
		if velocity.y == 0:
			anim.play("Run")
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		if velocity.y == 0:
			anim.play("Idle")
	move_and_slide()
